Skip to content

Add Parallel Agents plugin to run subagents concurrently#1

Open
prostonoob wants to merge 2 commits intodevfrom
codex/explain-how-task-algorithm-works
Open

Add Parallel Agents plugin to run subagents concurrently#1
prostonoob wants to merge 2 commits intodevfrom
codex/explain-how-task-algorithm-works

Conversation

@prostonoob
Copy link
Owner

Motivation

  • Provide a way to run multiple independent subagent jobs concurrently to avoid the core session loop's sequential blocking behavior.
  • Expose a small, ready-to-use API to launch, monitor, and wait for parallel subagent tasks.
  • Support typical workflows where the main agent can continue work while subagents run independently.

Description

  • Add .opencode/plugins/parallel-agents.ts which implements a ParallelAgentsPlugin that exposes tools agents_start, agents_status, and agents_wait and tracks jobs in an in-memory Map.
  • agents_start creates separate sessions and prompts up to 8 subagents in parallel and returns job ids, agents_status returns current job state and outputs, and agents_wait polls until selected jobs finish (with an optional timeout) using Bun.sleep for polling.
  • Add .opencode/README.parallel-agents.md with usage instructions and explains typical flow and how to enable the plugin via opencode.json.
  • Inject an experimental.chat.system.transform hint recommending the agents_start/agents_status/agents_wait flow for multi-task requests.

Testing

  • No automated tests were run for this change.

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a8cd789011

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

parts: [{ type: "text", text: item.prompt }],
},
})
.then((res) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Catch rejected prompt requests and mark jobs failed

The background client.session.prompt(...) call only uses .then(...) without a rejection handler, so transport-level failures (for example, fetch/network abort errors) leave the job in running forever. In that case agents_wait will keep polling until timeout and never surface the real failure, which makes parallel runs nondeterministic and hard to recover from.

Useful? React with 👍 / 👎.

jobs: tool.schema.array(tool.schema.string()).optional(),
},
async execute(args) {
const ids = args.jobs?.length ? args.jobs : Array.from(map.keys())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Scope job status queries to the requesting session

agents_status defaults to Array.from(map.keys()) while map is module-global, so a caller can retrieve jobs (including outputs and session IDs) started by other chats/sessions in the same process. In any shared runtime this leaks cross-session data; statuses should be filtered by owner session (or equivalent access check) before returning results.

Useful? React with 👍 / 👎.

const jid = id()
const desc = item.description?.trim() || "parallel task"

const created = await client.session.create({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle session.create rejection per task in agents_start

Each task awaits client.session.create(...) inside a Promise.all, so if one create request rejects, the whole agents_start call rejects and the caller receives no job IDs, even though other tasks may already have been launched. This makes partial failures unrecoverable; create errors should be caught per task and converted into per-job error states instead of aborting the entire batch.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant